<template>
  <div>
    <van-button
      :icon="isLike == 1 ? 'good-job' : 'good-job-o'"
      type="primary"
      class="starbtn"
      @click="likeingFn"
      :loading="likeing"
    ></van-button>
  </div>
</template>
<script>
import { likeingOutApi, likeingGoApi } from "@/api/article";
export default {
  model: {
    prop: "isLike",
    event: "isLikeedFn",
  },
  props: {
    isLike: [Number, String],

    artId: [Number, String],
  },
  data() {
    return {
      likeing: false,
    };
  },
  methods: {
    async likeingFn() {
      console.log(this.artId);
      try {
        let artid = this.artId;
        this.likeing = true;
        if (this.isLike == 1) {
          //取消点赞
          await likeingOutApi(artid);
          //修改视图
          this.$emit("isLikeedFn", -1);
          this.$toast.success("取消收藏");
          console.log(artid);
        } else {
          //点赞
          await likeingGoApi(artid);
          //修改视图
          this.$emit("isLikeedFn", 1);
          this.$toast.success("收藏成功");
          console.log(artid);
        }
        this.likeing = false;
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>
<style scoped lang="less">
/deep/.starbtn {
  background: #fff;
  border: 0px;
  color: #3a3a3a;
  .van-icon-good-job-o {
    color: #3a3a3a;
  }
  .van-icon-good-job {
    color: red;
  }
}
</style>
